package utility.alarm;

import java.io.IOException;
import java.util.Calendar;
import java.util.Vector;

import junit.framework.Assert;
import android.content.Context;

public class StringUlti {
	private final static StringUlti strUlti = new StringUlti();

	public static StringUlti getInstance() {
		return strUlti;
	}

	public static String separateListDay = ", ";

	public String formatTime(int hourOfDay, int minute, String ampm) {
		return pad(hourOfDay) + ":" + pad(minute) + " " + ampm;
	}
	
	public String formatDate(int dayOfWeek, int dayOfMonth, int month, int year) {
		return formatDayOfWeek(dayOfWeek) + ", " + dayOfMonth + "/" + (month+1) + "/" +year;
	}

	public String getListDays(Vector<Integer> listDay) {
		String list = "";
		if (listDay.size() == 7)
			list = "Every Day";
		else if (listDay.size() == 2 && listDay.get(0) == Calendar.SATURDAY
				&& listDay.get(1) == Calendar.SUNDAY)
			list = "Weekend";
		else {
			for (int i = 0; i < listDay.size(); i++) {
				if (i == listDay.size() - 1)
					list += formatDayOfWeek(listDay.get(i));
				else
					list += formatDayOfWeek(listDay.get(i)) + separateListDay;
			}
		}
		return list;
	}

	public String getAM_PM(int ampm) {
		if (ampm == 0)
			return "AM";
		else
			return "PM";
	}

	public int formatHour(int hourOfDay) {
		int hour = hourOfDay;
		if (hourOfDay > 12) {
			hour = hourOfDay - 12;
		}
		return hour;
	}

	public String pad(int c) {
		if (c >= 10)
			return Integer.toString(c);
		else
			return "0" + Integer.toString(c);
	}

	public String formatDayOfWeek(int c) {
		String day = "";
		switch (c) {
		case Calendar.MONDAY:
			day = "Mon";
			break;
		case Calendar.TUESDAY:
			day = "Tue";
			break;
		case Calendar.WEDNESDAY:
			day = "Wed";
			break;
		case Calendar.THURSDAY:
			day = "Thu";
			break;
		case Calendar.FRIDAY:
			day = "Fri";
			break;
		case Calendar.SATURDAY:
			day = "Sat";
			break;
		case Calendar.SUNDAY:
			day = "Sun";
			break;
		}
		return day;
	}

	public String formatOperation(int c) {
		String operation = "";
		switch (c) {
		case MathRandom.OPERATION_PLUS:
			operation = "+";
			break;
		case MathRandom.OPERATION_SUB:
			operation = "-";
			break;
		case MathRandom.OPERATION_MULTI:
			operation = "x";
			break;
		case MathRandom.OPERATION_DIV:
			operation = ":";
			break;
		}
		return operation;
	}

	public double sizeMB(String sizeKB) {
		return (double) (Math
				.round(Double.parseDouble(sizeKB) / 1024 / 1024 * 100.0) / 100.0);
	}

	public String duration(String ms) {
		int milisecond = Integer.parseInt(ms);
		int minute = milisecond / (60 * 1000);
		int second = (milisecond - (minute * 60 * 1000)) / 1000;
		String dura = minute + ":" + second;
		return dura;
	}

	public String[] getAllFilesInAsset(Context context, String path) {
		Assert.assertNotNull(context);
		try {
			return context.getAssets().list(path);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
